@extends('layouts.main')

@section('title', '添加开票信息')

@section('content')
<h3>@yield('title')</h3>
<div class="btn-group" role="group">
  	<a href="{{ action('BusinessData\InvoiceDetailsController@index') }}" class="btn btn-primary">返回列表</a>
</div>

<form class="form-horizontal" method="post" action="{{ action('BusinessData\InvoiceDetailsController@store') }}">
    @csrf

    <div class="form-group">
		<label for="year" class="col-sm-2 control-label">年份</label>
		<div class="col-sm-6">
			<select class="form-control" id="year" name="year">
			<option>请选择年份</option>
			@for($i = 2020; $i <= 2030; $i++)
			<option value="{{ $i }}" @if(old('year') == $i) selected @endif>{{ $i }}</option>
			@endfor
			</select>
			@if($errors->first('year'))
			<p class="help-block error">{{ $errors->first('year') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="month" class="col-sm-2 control-label">月份</label>
		<div class="col-sm-6">
			<select class="form-control" id="month" name="month">
			<option>请选择月份</option>
			@for($i = 1; $i <= 12; $i++)
			<option value="{{ $i }}" @if(old('month') == $i) selected @endif>{{ $i }}</option>
			@endfor
			</select>
			@if($errors->first('month'))
			<p class="help-block error">{{ $errors->first('month') }}</p>
			@endif
		</div>
    </div>

    <div class="form-group">
		<label for="sales_order_no" class="col-sm-2 control-label">销售订单号</label>
		<div class="col-sm-3">
			<input class="form-control" id="sales_order_no" name="sales_order_no" placeholder="请输入销售订单号" value="{{ old('sales_order_no') }}">
			@if($errors->first('sales_order_no'))
			<p class="help-block error">{{ $errors->first('sales_order_no') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="sales_order_line_no" class="col-sm-2 control-label">销售订单行号</label>
		<div class="col-sm-3">
			<input class="form-control" id="sales_order_line_no" name="sales_order_line_no" placeholder="请输入销售订单行号" value="{{ old('sales_order_line_no') }}">
			@if($errors->first('sales_order_line_no'))
			<p class="help-block error">{{ $errors->first('sales_order_line_no') }}</p>
			@endif
		</div>
    </div>

    <div class="form-group">
		<label for="material" class="col-sm-2 control-label">物料编码</label>
		<div class="col-sm-3">
			<input class="form-control" id="material" name="material" placeholder="请输入物料编码" value="{{ old('material') }}">
			@if($errors->first('material'))
			<p class="help-block error">{{ $errors->first('material') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="quantity" class="col-sm-2 control-label">开票数量</label>
		<div class="col-sm-3">
		  <input class="form-control" id="quantity" name="quantity" placeholder="请输入开票数量" value="{{ old('quantity') }}">
		  @if($errors->first('quantity'))
		  <p class="help-block error">{{ $errors->first('quantity') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="total_price_tax_discount" class="col-sm-2 control-label">开票总价(含税)(折扣前)</label>
		<div class="col-sm-3">
		  <input class="form-control" id="total_price_tax_discount" name="total_price_tax_discount" placeholder="请输入开票总价(含税)(折扣前)" value="{{ old('total_price_tax_discount') }}">
		  @if($errors->first('total_price_tax_discount'))
		  <p class="help-block error">{{ $errors->first('total_price_tax_discount') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="total_price_tax" class="col-sm-2 control-label">开票总价(含税)</label>
		<div class="col-sm-3">
		  <input class="form-control" id="total_price_tax" name="total_price_tax" placeholder="请输入开票总价(含税)" value="{{ old('total_price_tax') }}">
		  @if($errors->first('total_price_tax'))
		  <p class="help-block error">{{ $errors->first('total_price_tax') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="total_price_no_tax" class="col-sm-2 control-label">开票总价(不含税)</label>
		<div class="col-sm-3">
		  <input class="form-control" id="total_price_no_tax" name="total_price_no_tax" placeholder="请输入开票总价(不含税)" value="{{ old('total_price_no_tax') }}">
		  @if($errors->first('total_price_no_tax'))
		  <p class="help-block error">{{ $errors->first('total_price_no_tax') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="tax" class="col-sm-2 control-label">税额</label>
		<div class="col-sm-3">
		  <input class="form-control" id="tax" name="tax" placeholder="请输入税额" value="{{ old('tax') }}">
		  @if($errors->first('tax'))
		  <p class="help-block error">{{ $errors->first('tax') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="discount" class="col-sm-2 control-label">折扣金额</label>
		<div class="col-sm-3">
		  <input class="form-control" id="discount" name="discount" placeholder="请输入折扣金额" value="{{ old('discount') }}">
		  @if($errors->first('discount'))
		  <p class="help-block error">{{ $errors->first('discount') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="surcharge" class="col-sm-2 control-label">附加费</label>
		<div class="col-sm-3">
		  <input class="form-control" id="surcharge" name="surcharge" placeholder="请输入附加费" value="{{ old('surcharge') }}">
		  @if($errors->first('surcharge'))
		  <p class="help-block error">{{ $errors->first('surcharge') }}</p>
		  @endif
		</div>
	</div>

	<div class="form-group">
		<label for="sales_order_type_code" class="col-sm-2 control-label">销售订单类型</label>
		<div class="col-sm-6">
			<select class="form-control" id="sales_order_type_code" name="sales_order_type_code">
			<option>请选择销售订单类型</option>
			@foreach($sales_order_types as $sales_order_type)
			<option value="{{ $sales_order_type->code }}" @if(old('sales_order_type_code') == $sales_order_type->code) selected @endif>{{ $sales_order_type->code.' --- '.$sales_order_type->code_desc }}</option>
			@endforeach
			</select>
			@if($errors->first('sales_order_type_code'))
			<p class="help-block error">{{ $errors->first('sales_order_type_code') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="project_type_code" class="col-sm-2 control-label">项目类型</label>
		<div class="col-sm-6">
			<select class="form-control" id="project_type_code" name="project_type_code">
			<option>请选择项目类型</option>
			@foreach($project_types as $project_type)
			<option value="{{ $project_type->code }}" @if(old('project_type_code') == $project_type->code) selected @endif>{{ $project_type->code.' --- '.$project_type->code_desc }}</option>
			@endforeach
			</select>
			@if($errors->first('project_type_code'))
			<p class="help-block error">{{ $errors->first('project_type_code') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="sales_organization_code" class="col-sm-2 control-label">销售组织</label>
		<div class="col-sm-6">
			<select class="form-control" id="sales_organization_code" name="sales_organization_code">
			<option>请选择销售组织</option>
			@foreach($sales_organizations as $sales_organization)
			<option value="{{ $sales_organization->code }}" @if(old('sales_organization_code') == $sales_organization->code) selected @endif>{{ $sales_organization->code.' --- '.$sales_organization->code_desc }}</option>
			@endforeach
			</select>
			@if($errors->first('sales_organization_code'))
			<p class="help-block error">{{ $errors->first('sales_organization_code') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="sales_region_code" class="col-sm-2 control-label">销售大区</label>
		<div class="col-sm-6">
			<select class="form-control" id="sales_region_code" name="sales_region_code">
				<option>请选择销售大区</option>
				@foreach($sales_regions as $sales_region)
				<option value="{{ $sales_region->code }}" @if(old('sales_region_code') == $sales_region->code) selected @endif>{{ $sales_region->code.' --- '.$sales_region->code_desc }}</option>
				@endforeach
			</select>
			@if($errors->first('sales_region_code'))
			<p class="help-block error">{{ $errors->first('sales_region_code') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="sales_office_code" class="col-sm-2 control-label">销售办事处</label>
		<div class="col-sm-6">
			<select class="form-control" id="sales_office_code" name="sales_office_code">
				<option>请选择销售办事处</option>
			</select>
			@if($errors->first('sales_office_code'))
			<p class="help-block error">{{ $errors->first('sales_office_code') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="distribution_channel_code" class="col-sm-2 control-label">分销渠道</label>
		<div class="col-sm-6">
			<select class="form-control" id="distribution_channel_code" name="distribution_channel_code">
				<option>请选择分销渠道</option>
				@foreach($distribution_channels as $distribution_channel)
				<option value="{{ $distribution_channel->code }}" @if(old('distribution_channel_code') == $distribution_channel->code) selected @endif>{{ $distribution_channel->code.' --- '.$distribution_channel->code_desc }}</option>
				@endforeach
			</select>
			@if($errors->first('distribution_channel_code'))
			<p class="help-block error">{{ $errors->first('distribution_channel_code') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="payer_id" class="col-sm-2 control-label">付款方id</label>
		<div class="col-sm-3">
			<input class="form-control" id="payer_id" name="payer_id" placeholder="请输入付款方id" value="{{ old('payer_id') }}">
			@if($errors->first('payer_id'))
			<p class="help-block error">{{ $errors->first('payer_id') }}</p>
			@endif
		</div>
    </div>

	<div class="form-group">
		<label for="salesman_id" class="col-sm-2 control-label">业务员工号</label>
		<div class="col-sm-3">
			<input class="form-control" id="salesman_id" name="salesman_id" placeholder="请输入业务员工号" value="{{ old('salesman_id') }}">
			@if($errors->first('salesman_id'))
			<p class="help-block error">{{ $errors->first('salesman_id') }}</p>
			@endif
		</div>
    </div>

    <div class="form-group">
		<div class="col-sm-offset-2 col-sm-10">
			<button type="submit" class="btn btn-primary">提交</button>
		</div>
    </div>
  </form>

<script>
	$(function() {
	  	//$('select').comboSelect();
  
		$("#sales_region_code").change(function(){
			var sales_region_code = $(this).val();
			$.post('/base_data/sales_office/get_data_by_parent', {
				'_token': '{{ csrf_token() }}',
				'code' : sales_region_code,
			},function(result){
				switch(result.status){
				case 0:
					var html_str = '<option>请选择销售办事处</option>';
					$('#sales_office_code').find("option").remove();
					for(var i = 0; i < result.data.length; i++){
						html_str += '<option value="'+ result.data[i].code + '">'+ result.data[i].code + ' --- ' + result.data[i].code_desc +'</option>';               
					}
					$("#sales_office_code").append(html_str);
					break;
				}
			});
		});
  
	});
</script>
@endsection